package com.rightsidetech.http.controller.admin.mall;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.DelReq;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.mall.dto.request.*;
import com.rightsidetech.mall.dto.response.BaesInfoDetailResp;
import com.rightsidetech.mall.dto.response.BaseInfoPageResp;
import com.rightsidetech.mall.dto.response.OptBaseInfoPageResp;
import com.rightsidetech.mall.service.MallBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/mall_base_info/")
@ShenyuSpringMvcClient(path = "/admin/mall_base_info/**")
@Api(tags = "Admin: 基础商品相关")
public class MallBaseInfoController extends BaseController {

    @Resource
    private MallBaseInfoService mallBaseInfoService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/save")
    @ApiOperation("添加基础商品")
    public ResponseData saveBaseInfo(@RequestBody BaseInfoReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallBaseInfoService.save(req,loginName,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public ResponseData<PageInfo<BaseInfoPageResp>> page(BaseInfoPageReq req){
         return mallBaseInfoService.page(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResponseData<BaesInfoDetailResp> getDetail(@RequestParam(value = "id",required = true) Long id){
         return mallBaseInfoService.getBaesDetail(id);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/update")
    @ApiOperation("修改基础商品")
    public ResponseData updateDetail(@RequestBody BaseInfoUpReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallBaseInfoService.update(req,loginName,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/del")
    @ApiOperation("删除基础商品")
    public ResponseData deleteBaseInfo(@RequestBody DelReq req){
        return mallBaseInfoService.isDelete(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/opt_list")
    @ApiOperation("选择商品列表")
    public ResponseData<PageInfo<OptBaseInfoPageResp>> optPageList(OptBaseInfoReq req){
         return mallBaseInfoService.optBaseInfo(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/opt_integral")
    @ApiOperation("选择积分(换购)商品列表")
    public ResponseData<PageInfo<OptBaseInfoPageResp>> optIntegral(OptBaseInfoReq req){
        return mallBaseInfoService.optIntegral(req);
    }


    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/create_specs")
    @ApiOperation("基础商品哪些规格创建过积分商品")
    public ResponseData<List<DetailSpecsReq>> createSpecs(Long id){
        return mallBaseInfoService.createSpecs(id);
    }


    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/create_specs_gift")
    @ApiOperation("基础商品哪些规格创建过换购商品")
    public ResponseData<List<DetailSpecsReq>> giftCreateSpecs(Long id){
       return mallBaseInfoService.createSpecsGift(id);
    }
}
